'use strict'

class suggestion {

    constructor() {
        this.param = '/'
    }

    //创建资源
    async post(c) {
        var openid = c.box.user.openid;
        var content = c.body.toString();
        try {
            var r0 = await c.service.psql.query(`select MAX(suggestion_id) from suggestion`);
            var count = r0.rows[0].max;
            if(count===null){
                count=1;
            }else{
                count++;
            }
            let sqltext1 = `INSERT INTO suggestion(openid,suggestion_content,suggestion_id) `
            +`values ('${openid}','${content}',${count})`
            var r1 = await c.service.psql.query(sqltext1);
            return c.send('success');
        } catch (err) {
            console.log(err);
            return c.status(500).send('err')
        }
    }
}

module.exports = suggestion